<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
      <div>
          <div>
              <label for="">学生姓名</label>
              <input type="text" id='name'>
          </div>
          <div>
            <label for="">年龄</label>
            <input type="text" id='age'>
          </div>
          <div>
            <label for="">性别</label>
              <input type="radio" checked name="gender" value="男">
              <label for="">男</label>
              <input type="radio"name="gender" value="女">
              <label for="">女</label>
          </div>
          <div>
            <label for="">分数</label>
            <input type="text" id='score'>
          </div>
          <div>
                <button id='addBtnh'>添加</button>
          </div>
      </div>
</body>
</html>
<script src="../lib/jquery.min.js"></script>
<script src='../utils/initAjaxHeader.js'></script>
<script>
let nameInput = $("#name");
let ageInput = $("#age");
let scoreInput = $("#score");
$("#addBtnh").click(()=>{
    let gender =$("input[type=radio]:checked");
    //console.log(gender.value);
    $.ajax({
        type:"post",
        url:"/api/student/add",
        data:{
           "name": nameInput.val(),
           "age": ageInput.val(),
           "gender": gender.val(),
           "score": scoreInput.val(),
        },
      /*   headers:{
            "Authorization":localStorage.getItem("_t")
        }, */
        dataType:"json",
        success(data){
            console.log(data);

            if(data.code==0){
                alert(data.msg);
              location.href= "./studentList.html";   
            }else{
               alert(data.msg);
               window.top.location.href= "../login.html";   
            }
        }
    })
});


</script>